#
#    Copyright 2006 Andrew Wilkinson <aw@cs.york.ac.uk>.
#
#    This file is part of PyScobble (http://lastfm.indiegigs.co.uk/pyscrobble)
#
#    PyScobble is free software; you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as published by
#    the Free Software Foundation; either version 2.1 of the License, or
#    (at your option) any later version.
#
#    PyScobble is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Lesser General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public License
#    along with PyScobble; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

from scrobble import Artist
from scrobble.utils import *

## A Last.fm Track
#
# Only the artist and track name are required to create a Track, the other
# parameters are optional and can be filled in later. Filling them in will provide
# more information to Last.fm when scrobbling tracks.
#
# @param artist An Artist object representing the artist who performed this track.
# @param name The name of the track.
# @param mbid A string containing the MusicBrainz ID.
# @param albumname A string containing the album the track is taken from.
# @param length The length of the track in seconds.
class Track(object):
    ## This class constructor
    #
    # @param self The implicit self parameter
    # @param artist An Artist object representing the artist who performed this track.
    # @param name The name of the track.
    # @param mbid A string containing the MusicBrainz ID.
    # @param albumname A string containing the album the track is taken from.
    # @param length The length of the track in seconds.
    def __init__(self, artist, name, mbid=None, albumname=None, length=None):
        assert isinstance(artist, Artist)
        self.__artist = artist
        self.__name = name
        self.__mbid = mbid
        self.__albumname = albumname
        self.__length = length

    def __getArtist(self):
        return self.__artist
    ## This Track's artist
    artist = property(__getArtist)
    def __getName(self):
        return self.__name
    ## The Track's name
    name = property(__getName)
    def __getMbId(self):
        return self.__mbid
    ## This Track's MusicBrainz ID
    mbid = property(__getMbId)
    def __getAlbumName(self):
        return self.__albumname
    def __setAlbumName(self, value):
        self.__albumname = value
    ## The Tracks' album name
    albumname = property(__getAlbumName, __setAlbumName)
    def __getLength(self):
        return self.__length
    def __setLength(self, value):
        self.__length = value
    ## The length of the track in seconds.
    length = property(__getLength, __setLength)

    ## Compares two Track objects
    def __cmp__(self, other):
        if self.mbid is not None and other.mbid is not None:
            return cmp(self.mbid, other.mbid)
        else:
            if cmp(self.artist, other.artist) == 0:
                return cmp(self.name, other.name)
            else:
                return cmp(self.artist, other.artist)

    ## Returns a string representation of the Track
    def __str__(self):
        return "%s - %s" % (repr(self.artist), repr(self.name))
    ## Returns a string representation of the Track
    def __repr__(self):
        return "<scrobble.Track(%s - %s)" % (repr(self.artist), repr(self.name))
